
$(function() {
	
	$('#date').datepicker(_date1_option);

	$("select[id='category_t']:visible").selectChain({
		target: $("select[id='type_t']:visible"),
		key: "code",
		value: "name",
		url: 'finance.php?do=Asset.ajax_category',
		data: { ajax: true }
	}).trigger('change');

	_change("input[id='category']:visible", "select[id^='category_t']:visible");
	
	_change("input[id='type']:visible", "select[id^='type_t']:visible");
	
	_change("input[id='unit']:visible", "select[id^='unit_t']:visible");
	
	Tip.emp('责任人');
	
	$('textarea').css("width", 400);
	
	var columns = [{
	    id: "#",
	    name: "",
	    width: 40,
	    behavior: "selectAndMove",
	    unselectable: true,
	    resizable: false,
	    cssClass: "cell-reorder"
	}, {
	    id: "name",
	    name: "名称",
	    field: "name",
	    width: 300,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "content",
	    name: "备注",
	    field: "content",
	    width: 120,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "ok",
	    name: "",
	    field: "ok",
	    width: 60,
	    cssClass: "cell-effort-driven",	    
	    cannotTriggerInsert: true,
	    formatter: Slick.Formatters.YesNo,
	    editor: Slick.Editors.Checkbox
	}];

	var options = {
		editable: true,
	    enableAddRow: true,
	    enableCellNavigation: true,
	    asyncEditorLoading: false,
	    rowHeight: 30    
	};	
	
	var grid = new Slick.Grid($("#myGrid"), data, columns, options);
	
	grid.onAddNewRow.subscribe(function (e, args) {
		var item = {name:"", content:"", ok: true};
		item.date = current_date();
		
	    $.extend(item, args.item);
	    data.push(item);
	    grid.invalidateRows([data.length - 1]);
	    grid.updateRowCount();
	    grid.render();
	});
	
	grid.onCellChange.subscribe(function(e, args) {
		
		item = args.item;
		currentCell = args.cell;
		currentRow = args.row;
	    grid.render();
	});
});
